package com.accp.vehiclecare.action.zbaction;

import com.accp.vehiclecare.biz.zbbiz.DimissionBiz;
import com.accp.vehiclecare.pojo.Dimissiontext;
import com.accp.vehiclecare.vo.zbvo.DimissionVo;
import com.accp.vehiclecare.vo.zbvo.StaffVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Api(tags="日志接口模块")
@RestController
@RequestMapping("/api/dim")
public class DimissionAction {
    @Autowired
    private DimissionBiz dbiz;

    @ApiOperation(value="分页查询职工信息", notes = "根据当前页数，每页多少行查询出分页数据", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="path", name = "p", value = "当前页数", example = "1", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="path", name = "s", value = "每页多少行", example = "3", required = true, dataType = "int")
    })
    @GetMapping("emp/{p}/{s}")
    public PageInfo<StaffVo> queryAllStaff(@PathVariable Integer p, @PathVariable Integer s) {
        return dbiz.queryStaff(p,s);
    }
    @ApiOperation(value="分页查询离职信息", notes = "根据当前页数，每页多少行查询出分页数据", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="path", name = "p", value = "当前页数", example = "1", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="path", name = "s", value = "每页多少行", example = "3", required = true, dataType = "int")
    })
    @GetMapping("{p}/{s}")
    public PageInfo<DimissionVo> queryAllDim(@PathVariable Integer p, @PathVariable Integer s) {
        return dbiz.queryDim(p,s);
    }
    @ApiOperation(value="删除", notes = "根据离职id进行删除", httpMethod = "DELETE")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="path", name = "id", value = "员工id", example = "1", required = true, dataType = "int")
    })
    @DeleteMapping("remove/{id}")
    public Map<String,Object> removeStaff(@PathVariable Integer id){
        Map<String,Object> message=new HashMap<String,Object>();
        boolean count=dbiz.removeDim(id);
        if (count){
            message.put("code","200");
            message.put("msg","ok");
        }
        return message;
    }
    @ApiOperation(value="新增日志", notes = "根据前端发送的离职信息进行新增", httpMethod = "POST")
    @PostMapping("add")
    public Map<String,Object> addStaff(@RequestBody Dimissiontext dim){
        Map<String,Object> message=new HashMap<String,Object>();
        boolean count= dbiz.addDim(dim);
        dbiz.modifyDim(dim.getEid());
        if (count){
            message.put("code","200");
            message.put("msg","ok");
        }
        return message;
    }
    @ApiOperation(value="修改日志", notes = "根据前端发送的离职信息进行离职", httpMethod = "GET")
    @GetMapping("modifyDim/{eid}")
    public Map<String,Object> modifyDim(@PathVariable Integer eid){
        Map<String,Object> message=new HashMap<String,Object>();
        boolean count= dbiz.modifyDim(eid);
        if (count){
            message.put("code","200");
            message.put("msg","ok");
        }
        return message;
    }
    @ApiOperation(value="修改日志", notes = "根据前端发送的离职信息进行回滚", httpMethod = "GET")
    @GetMapping("modifyWork/{eid}")
    public Map<String,Object> mofifyWork(@PathVariable Integer eid){
        Map<String,Object> message=new HashMap<String,Object>();
        boolean count= dbiz.modifyWork(eid);
        if (count){
            message.put("code","200");
            message.put("msg","ok");
        }
        return message;
    }
}
